package com.greenline.search.test.httprequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: liulei
 * Date: 13-9-25
 * Time: 上午9:54
 * To change this template use File | Settings | File Templates.
 */
public class PerformanceInfo {
    private Logger logger = LoggerFactory.getLogger(PerformanceInfo.class);
    private Double averageResponseTime;
    private Double totalResponseTime;
    private Integer requestCount;
    private Integer returnZeroRequestCount = 0;

    private List<ResponseInfo> responseInfoList;

    public PerformanceInfo(){}

    public PerformanceInfo(List<ResponseInfo> responseInfoList){
        this.responseInfoList = responseInfoList;
        this.requestCount = responseInfoList.size();
        totalResponseTime = 0.0;
        for(ResponseInfo responseInfo : responseInfoList){
            totalResponseTime += responseInfo.getQueryTimeMills();
            if(responseInfo.getReturnCount() == 0){
                ++returnZeroRequestCount;
            }
        }
        averageResponseTime = totalResponseTime / requestCount;
    }

    public void printKeywordAndReturnCountLog(){
        for(ResponseInfo info : responseInfoList){
            logger.info("&&\t"+info.getKeyword()+"\t"+info.getReturnCount());
        }
    }

    public void printDetail(){
        logger.info("The total response time is " + totalResponseTime + " milliseconds.");
        logger.info("The request count is " + requestCount + ".");
        logger.info("The return zero request count is " + returnZeroRequestCount + ".");
        logger.info("The average response time is " + averageResponseTime + " milliseconds.");
    }
}
